'''
Created on 2011-7-11

@author: Administrator
'''
from google.appengine.ext import webapp, db
from model import Photo
from google.appengine.ext.webapp.util import run_wsgi_app


class PhotoUploadHandler(webapp.RequestHandler):

    def post(self):
        try:
            content = self.request.get('file', '')
            fileName = self.request.get('name', '')
            gps = self.request.get('gps')
            photoKey = Photo(name=fileName, content=db.Blob(content), gps=gps).put()
            rst = {'rst':'ok', 'photo_key':photoKey}
        except:
            rst = {'rst':'error'}
        self.response.headers['Content-Type'] = 'text/json'
        self.response.out.write(rst)


def main():
    application = webapp.WSGIApplication([(r'/upload', PhotoUploadHandler)], debug=True)
    run_wsgi_app(application)

if __name__ == '__main__':
    main()
